<?php
/**
* 登录验证
*/
class UserIdentity extends CUserIdentity
{
    private $_id;
 
    public function authenticate()
    { 
        $record=User::model()->findByAttributes(array('email'=>$this->username));
        if($record===null){  
            $this->errorCode=self::ERROR_USERNAME_INVALID;
        }
        else if(!$record->vpassword($this->password)){
            $this->errorCode=self::ERROR_PASSWORD_INVALID;  
        }
        else
        {
        	//当前用户没有激活
        	if($record->active != 1 ){
        		throw new CHttpException(403,"当前用户没有激活，请先激活该用户！再来登录！");
        	}
        	/**
        	* 判断是否是管理员
        	*/
        	if($record->flag == 1) 
        		$this->setState('isadmin', true); 
        	else
        		$this->setState('isadmin', false);
        	
            $this->_id=$record->id;
            $this->setState('email', $record->email);
            $this->errorCode=self::ERROR_NONE;
        }
        return !$this->errorCode;
    }
 
    public function getId()
    {
        return $this->_id;
    }
}